package com.missilike.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.missilike.biz.IMilAccountService;
import com.missilike.core.result.CommonResult;
import com.missilike.core.utils.ResultUtils;
import com.missilike.core.utils.SecurityUtils;
import com.missilike.domain.request.MilAccountStatusForm;
import com.missilike.domain.request.SysUserForm;
import com.missilike.domain.response.MilAccountInfo;
import com.missilike.repository.entity.MilAccount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author kin
 * @since 2018-12-13
 */
@RestController
@RequestMapping("/api/mil/account")
public class MilAccountController {

    private final IMilAccountService milAccountService;

    @Autowired
    public MilAccountController(IMilAccountService milAccountService) {
        this.milAccountService = milAccountService;
    }

    @RequestMapping(value = "page", method = RequestMethod.GET)
    public CommonResult list(@RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
                             @RequestParam(value = "pageSize", required = false, defaultValue = "20") int pageSize,
                             @RequestParam(value = "account", required = false, defaultValue = "") String account) {
        IPage<MilAccountInfo> accountList = milAccountService.getList(new Page<>(pageNum, pageSize),account);
        return ResultUtils.ok(accountList);
    }

    @RequestMapping(value = "info/{accountId}", method = RequestMethod.GET)
    public CommonResult info(@PathVariable("accountId") String accountId) {
        return ResultUtils.ok(milAccountService.getAccount(accountId));
    }


    @RequestMapping(value = "update", method = RequestMethod.POST)
    public CommonResult update(@RequestBody MilAccount milAccount) {
        milAccountService.updateById(milAccount);
        return ResultUtils.ok();
    }

    @RequestMapping(value = "status", method = RequestMethod.POST)
    public CommonResult status(@RequestBody MilAccountStatusForm milAccountStatusForm) {
        milAccountService.status(milAccountStatusForm);
        return ResultUtils.ok();
    }

}

